package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import com.itheima.pojo.Article;
import com.itheima.service.ArticleService;
import com.itheima.utile.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    ArticleService articleService;
    @Autowired
    IdWorker idWorker;
    @GetMapping("/{id}")
    public Result get(@PathVariable("id") String id){
        Article article = articleService.get(id);
        return new Result(true, StatusCode.OK,"查询成功",article);
    }
    @PostMapping("/{id}")
    public Result add(@RequestBody Article article){
        long l = idWorker.nextId();
        article.setId(String.valueOf(l));
        articleService.add(article);
        return new Result(true, StatusCode.OK,"添加成功");
    }

}
